import * as fs from "fs-extra";
import * as path from "path";
import { IProxy } from '@/typing';
import { Subject } from 'rxjs';
import axios from 'axios';

export function fetchSource(updater$: Subject<IProxy>) {
  const sourceDir = path.join(__dirname, "sources")
  const sources = fs.readdirSync(sourceDir).filter(e => e.slice(-3) === ".js")
  sources.forEach(e => {
    // @ts-ignore
    new (require(path.join(__dirname, `sources/${e}`)).default)().fetch(updater$)
    // new ProxySourceClass().fetch()
  })
}

export function debugSource() {
  const sourceDir = path.join(__dirname, "sources")
  const sources = fs.readdirSync(sourceDir).filter(e => e.slice(-3) === ".js")
  sources.forEach(e => {
    // @ts-ignore
    let sourceInstance = new (require(path.join(__dirname, `sources/${e}`)).default)()
    if (typeof sourceInstance.debug === "function") {
      sourceInstance.debug()
    }
    // new ProxySourceClass().fetch()
  })
}